package com.project.web.wechat.controller.app;

import com.project.common.core.utils.exception.Result;
import com.project.common.core.utils.weChat.WeChatMiniUtil;
import com.project.web.wechat.controller.common.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 微信小程序API
 *
 * @Author: wyy
 * @Date: 2020-04-08 13:00
 */
@Api(tags = "微信小程序API")
@RestController("WeChatMiniController")
@RequestMapping("/weChat/mini")
public class WeChatMiniController extends BaseController {
    public static final Logger log = LoggerFactory.getLogger(WeChatMiniController.class);

    /**
     * 生成无限制小程序码
     *
     * @param scene   场景值
     * @param pageUri 小程序页面路由地址
     * @param width   小程序码大小
     * @return
     */
    @ApiOperation(value = "生成无限制小程序码")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "scene", value = "场景值", dataType = "String", required = true),
            @ApiImplicitParam(paramType = "query", name = "pageUri", value = "小程序页面路由地址", dataType = "String", required = true),
            @ApiImplicitParam(paramType = "query", name = "width", value = "小程序码大小", dataType = "int", required = true)
    })
    @PostMapping(value = "/getMiniQrCodeImg")
    public Result<String> getMiniQrCodeImg(String scene, String pageUri, int width) {
        String qrCodeImgPath = WeChatMiniUtil.getMiniQrCodeImg(scene, pageUri, width, null, false);
        return getResult(qrCodeImgPath);
    }
}
